package com.oocl.servlet;


import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.exception.MyException;
import com.oocl.pojo.Customer;
import com.oocl.service.CustomerService;
import com.oocl.service.FavcService;
import com.oocl.service.impl.CustomerServiceFactory;
import com.oocl.service.impl.FavcServiceFactory;
import com.oocl.service.impl.ServiceFactory;


public class ListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		CustomerServiceFactory cFactory = null;
		FavcServiceFactory fFactory = null;
		try {
			cFactory = (CustomerServiceFactory) ServiceFactory.getServiceFactory(CustomerServiceFactory.CUSTOMER);
            fFactory = (FavcServiceFactory) ServiceFactory.getServiceFactory(FavcServiceFactory.FAVC);
			CustomerService cSer =  cFactory.getService();
			FavcService fSer = fFactory.getService();
			List<Customer> list = cSer.getList();
			for(Customer c :list){
				String favcNames = fSer.getNames(c.getId());
				c.setFavcStr(favcNames);
			}
			request.setAttribute("list", list);
			request.getRequestDispatcher("list.jsp").forward(request, response);
		} catch (MyException e) {
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	   
		doGet(request,response);
	}
}
